import { response } from "express"
import { request } from "express"
import CODE from "../../config/data.config.js";
import * as service from '../../service/service.js'

class AdopterController {
    /**
     * @param {request} req
     * @param {response} res
     */
    static async InsertAdopter(req, res, next) {
        try {
            const status = await service.AdopterService.InsertAdopter(req.body)
            if (status) {
                res.send({
                    msg: '添加成功',
                    code: 1,
                    data: status
                })
            } else res.send({ msg: '添加失败', code: CODE.CODE_FAIL })
        } catch (error) {
            next(error)
        }
    }
    /**
     * @param {request} req
     * @param {response} res
     * get请求响应
     */
    static async GetAdopter(req, res, next) {
        try {
            let { onlyIsPassed, condition } = req.query
            const result = await service.AdopterService.GetAdopter(undefined, onlyIsPassed, condition)
            res.send({
                msg: '查询成功',
                code: 1,
                data: result
            }).end()
        } catch (error) {
            next(error)
        }
    }

    /**
     * 修改
     * @param {request} req
     * @param {response} res
     */
    static async EditAdopter(req, res, next) {
        try {
            let { model, columns } = req.body
            let state = await service.AdopterService.EditAdopter(model, columns)
            if (state) {
                res.send({
                    msg: '修改成功',
                    code: CODE.CODE_OK,
                    data: state
                })
            } else res.send({
                msg: '修改失败',
                code: CODE.CODE_FAIL,
                data: state
            })
        } catch (error) {
            next(error)
        }
    }
}

export default AdopterController